<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <div style="margin: 10px 10px 10px 10px">
                <div id="searchParam">
                    <div class="layui-form layui-form-pane">
                        <div class="layui-form-item">
                            <div class="layui-input-inline">
                                <input type="groupName" id="groupName" class="layui-input" autocomplete="off" placeholder="请输群聊名称">
                            </div>
                            <div class="layui-inline">
                                <button onclick="search()" class="layui-btn layui-btn-primary" lay-submit
                                        lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" th:value="${id} " id="id" name="id" class="layui-input">
                </div>
            </div>

            <table class="layui-hide" id="showTable" lay-filter="showTable"></table>


        </fieldset>
    </div>
</div>

</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var id = $("#id").val();
    var callbackdata;
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        //加载table
        tableIns1 = table.render({
            elem: '#showTable'
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , url: '/wechatGroup/listByPage'
            , method: 'POST'
            , where: {
                robotId: id
            }
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                console.log(res);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'groupName', title: '群名称'},

                ]
            ]

        });
        table.on('row(showTable)', function (e) {
        })
    });

    //执行查询
    function search() {
        //这里以搜索为例
        tableIns1.reload({
            where: { //设定异步数据接口的额外参数，任意设
                groupName: $("#groupName").val()
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    };
    //表单数据的回调
    callbackdata = function () {
        var selectData = layui.table.checkStatus('showTable').data;
        var data = {
            arr: [],
            name: []
        }

        selectData.forEach(function (item) {
            data.arr.push(item.id)
            data.name.push(item.groupName)
        })
        return data
    }
</script>